<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Stream Based Generator API</title>
<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../../index.html" title="Spirit 2.5.8">
<link rel="up" href="../generate_api.html" title="Generator API">
<link rel="prev" href="iterator_api.html" title="Iterator Based Generator API">
<link rel="next" href="create_generator.html" title="API for Automatic Generator Creation">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="iterator_api.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../generate_api.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="create_generator.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="spirit.karma.reference.generate_api.stream_api"></a><a class="link" href="stream_api.html" title="Stream Based Generator API">Stream
          Based Generator API</a>
</h5></div></div></div>
<h6>
<a name="spirit.karma.reference.generate_api.stream_api.h0"></a>
            <span class="phrase"><a name="spirit.karma.reference.generate_api.stream_api.description"></a></span><a class="link" href="stream_api.html#spirit.karma.reference.generate_api.stream_api.description">Description</a>
          </h6>
<p>
            The library provides a couple of Standard IO <a href="http://www.cppreference.com/wiki/io/io_flags#manipulators" target="_top">Manipulators</a>
            allowing to integrate <span class="emphasis"><em>Spirit.Karma</em></span> output generation
            facilities with Standard output streams. These generator manipulators
            have two forms. The first form, <code class="computeroutput"><span class="identifier">format</span></code>,
            concatenates the output generated by the involved components without
            inserting any output in between. The second, <code class="computeroutput"><span class="identifier">format_delimited</span></code>,
            intersperses the output generated by the involved components using the
            given delimiter generator. Both versions can take in attributes by (constant)
            reference that hold the attribute values to output.
          </p>
<h6>
<a name="spirit.karma.reference.generate_api.stream_api.h1"></a>
            <span class="phrase"><a name="spirit.karma.reference.generate_api.stream_api.header"></a></span><a class="link" href="stream_api.html#spirit.karma.reference.generate_api.stream_api.header">Header</a>
          </h6>
<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/stream/format_manip.hpp&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">karma_format</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<p>
            For variadic attributes:
          </p>
<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/stream/format_manip_attr.hpp&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">karma_format_attr</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<p>
            The variadic attributes version of the API allows one or more attributes
            to be passed into the <code class="computeroutput"><span class="identifier">format</span></code>
            manipulators. The manipulators taking two or more attributes are usable
            when the generator expression is a <a class="link" href="../operator/sequence.html" title="Sequence Generator (a &lt;&lt; b)">Sequence
            (<code class="computeroutput"><span class="special">&lt;&lt;</span></code>)</a> only.
            In this case each of the attributes passed have to match the corresponding
            part of the sequence.
          </p>
<p>
            For the API functions deducing the correct (matching) generator type
            from the supplied attribute type:
          </p>
<pre class="programlisting"><span class="comment">// forwards to &lt;boost/spirit/home/karma/format_auto.hpp&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">spirit</span><span class="special">/</span><span class="identifier">include</span><span class="special">/</span><span class="identifier">karma_format_auto</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
</pre>
<p>
            Also, see <a class="link" href="../../../structure/include.html" title="Include">Include Structure</a>.
          </p>
<h6>
<a name="spirit.karma.reference.generate_api.stream_api.h2"></a>
            <span class="phrase"><a name="spirit.karma.reference.generate_api.stream_api.namespace"></a></span><a class="link" href="stream_api.html#spirit.karma.reference.generate_api.stream_api.namespace">Namespace</a>
          </h6>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                    <p>
                      Name
                    </p>
                  </th></tr></thead>
<tbody>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">format</span></code>
                    </p>
                  </td></tr>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">format_delimited</span></code>
                    </p>
                  </td></tr>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">delimit_flag</span><span class="special">::</span><span class="identifier">predelimit</span></code>
                    </p>
                  </td></tr>
<tr><td>
                    <p>
                      <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">spirit</span><span class="special">::</span><span class="identifier">karma</span><span class="special">::</span><span class="identifier">delimit_flag</span><span class="special">::</span><span class="identifier">dont_predelimit</span></code>
                    </p>
                  </td></tr>
</tbody>
</table></div>
<h6>
<a name="spirit.karma.reference.generate_api.stream_api.h3"></a>
            <span class="phrase"><a name="spirit.karma.reference.generate_api.stream_api.synopsis"></a></span><a class="link" href="stream_api.html#spirit.karma.reference.generate_api.stream_api.synopsis">Synopsis</a>
          </h6>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">spirit</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">karma</span>
<span class="special">{</span>
    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
    <span class="identifier">format</span><span class="special">(</span>
        <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">xpr</span><span class="special">);</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Expr</span>
      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="keyword">typename</span> <span class="identifier">AttrN</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
    <span class="identifier">format</span><span class="special">(</span>
        <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">xpr</span>
      <span class="special">,</span> <span class="identifier">Attr1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attrN</span><span class="special">);</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Delimiter</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
    <span class="identifier">format_delimited</span><span class="special">(</span>
        <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
      <span class="special">,</span> <span class="identifier">Delimiter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">d</span>
      <span class="special">,</span> <span class="identifier">BOOST_SCOPED_ENUM</span><span class="special">(</span><span class="identifier">delimit_flag</span><span class="special">)</span> <span class="identifier">pre_delimit</span> <span class="special">=</span> <span class="identifier">delimit_flag</span><span class="special">::</span><span class="identifier">dont_predelimit</span><span class="special">);</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Delimiter</span>
      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="keyword">typename</span> <span class="identifier">AttrN</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
    <span class="identifier">format_delimited</span><span class="special">(</span>
        <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
      <span class="special">,</span> <span class="identifier">Delimiter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">d</span>
      <span class="special">,</span> <span class="identifier">Attr1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attrN</span><span class="special">);</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Expr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Delimiter</span>
      <span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr1</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="keyword">typename</span> <span class="identifier">AttrN</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
    <span class="identifier">format_delimited</span><span class="special">(</span>
        <span class="identifier">Expr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">expr</span>
      <span class="special">,</span> <span class="identifier">Delimiter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">d</span>
      <span class="special">,</span> <span class="identifier">BOOST_SCOPED_ENUM</span><span class="special">(</span><span class="identifier">delimit_flag</span><span class="special">)</span> <span class="identifier">pre_delimit</span>
      <span class="special">,</span> <span class="identifier">Attr1</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr1</span><span class="special">,</span> <span class="identifier">Attr2</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">AttrN</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attrN</span><span class="special">);</span>
<span class="special">}}}</span>
</pre>
<p>
            <span class="emphasis"><em>Spirit.Karma</em></span> generator API functions based on the
            automatic creation of the matching generator type:
          </p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">spirit</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">karma</span>
<span class="special">{</span>
    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Delimiter</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
    <span class="identifier">format_delimited</span><span class="special">(</span>
        <span class="identifier">Attr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">attr</span>
      <span class="special">,</span> <span class="identifier">Delimiter</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">d</span>
      <span class="special">,</span> <span class="identifier">BOOST_SCOPED_ENUM</span><span class="special">(</span><span class="identifier">delimit_flag</span><span class="special">)</span> <span class="identifier">pre_delimit</span> <span class="special">=</span> <span class="identifier">delimit_flag</span><span class="special">::</span><span class="identifier">dont_predelimit</span><span class="special">);</span>

    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Attr</span><span class="special">&gt;</span>
    <span class="keyword">inline</span> <span class="special">&lt;</span><span class="identifier">unspecified</span><span class="special">&gt;</span>
    <span class="identifier">format</span><span class="special">(</span>
        <span class="identifier">Attr</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">xpr</span><span class="special">);</span>
<span class="special">}}}</span>
</pre>
<p>
            All functions above return a standard IO stream manipulator instance
            (see <a href="http://www.cppreference.com/wiki/io/io_flags#manipulators" target="_top">Manipulators</a>),
            which when streamed to an output stream will result in generating the
            output as emitted by the embedded <span class="emphasis"><em>Spirit.Karma</em></span> generator
            expression. Any error occurring during the invocation of the <span class="emphasis"><em>Spirit.Karma</em></span>
            generators will be reflected in the streams status flag (<code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios_base</span><span class="special">::</span><span class="identifier">failbit</span></code> will be set).
          </p>
<p>
            The maximum number of supported arguments is limited by the preprocessor
            constant <code class="computeroutput"><span class="identifier">SPIRIT_ARGUMENTS_LIMIT</span></code>.
            This constant defaults to the value defined by the preprocessor constant
            <code class="computeroutput"><span class="identifier">PHOENIX_LIMIT</span></code> (which
            in turn defaults to <code class="computeroutput"><span class="number">10</span></code>).
          </p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
              The variadic manipulators with two or more attributes internally combine
              (constant) references to all passed attributes into a <code class="computeroutput"><span class="identifier">fusion</span><span class="special">::</span><span class="identifier">vector</span></code> and forward this as a combined
              attribute to the corresponding manipulator taking one attribute.
            </p></td></tr>
</table></div>
<p>
            The <code class="computeroutput"><span class="identifier">format_delimited</span></code>
            manipulators not taking an explicit <code class="computeroutput"><span class="identifier">delimit_flag</span></code>
            as one of their arguments don't invoke the passed delimiter before starting
            to generate output from the generator expression. This can be enabled
            by using the other version of that manipulator while passing <code class="computeroutput"><span class="identifier">delimit_flag</span><span class="special">::</span><span class="identifier">predelimit</span></code> to the corresponding argument.
          </p>
<h6>
<a name="spirit.karma.reference.generate_api.stream_api.h4"></a>
            <span class="phrase"><a name="spirit.karma.reference.generate_api.stream_api.template_parameters"></a></span><a class="link" href="stream_api.html#spirit.karma.reference.generate_api.stream_api.template_parameters">Template
            parameters</a>
          </h6>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                    <p>
                      Parameter
                    </p>
                  </th>
<th>
                    <p>
                      Description
                    </p>
                  </th>
</tr></thead>
<tbody>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">Expr</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      An expression that can be converted to a Karma generator.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">Delimiter</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      Generator used to delimit the output of the expression components.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">Attr</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      An attribute type utilized to create the corresponding generator
                      type from.
                    </p>
                  </td>
</tr>
<tr>
<td>
                    <p>
                      <code class="computeroutput"><span class="identifier">Attr1</span></code>, <code class="computeroutput"><span class="identifier">Attr2</span></code>, ..., <code class="computeroutput"><span class="identifier">AttrN</span></code>
                    </p>
                  </td>
<td>
                    <p>
                      One or more attributes.
                    </p>
                  </td>
</tr>
</tbody>
</table></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="iterator_api.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../generate_api.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="create_generator.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
